package com.cloudy.cloudspider.search;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;
/**
 * Created by cloudy.xie on 18/1/15.
 */
public class GsonHelper {
    //解析简单Json数据
    public static <T> T parseJson(String jsonData,Class<T> entityType){
        Gson gson=new Gson();
        T t=gson.fromJson(jsonData,entityType);
        return t;
    }

    //解析JsonArray数据
    public static <T> List<T> parseJsonArray(String jsonArrayData,Type type){
        Gson gson = new Gson();
        List<T> list=gson.fromJson(jsonArrayData,type);
        return list;
    }

    public static <T> String toJson(T t){
        Gson gson=new Gson();
        return gson.toJson(t);
    }
}
